#!D:\python\fp1\Scripts\python.exe
#-*- coding:UTF-8 -*-

# CGI处理模块
import cgi, cgitb 
import codecs, sys ,time,os
sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer)
cgitb.enable()
form = cgi.FieldStorage()

# 获取文件名
fileitem = form['userimg']
filetitle = form.getvalue('filetitle')

 

# 检测文件是否上传
if fileitem.filename:
   # 设置文件路径 
   fn = os.path.basename(fileitem.filename)

   path=os.getcwd()+'/tmp/'
   if os.path.isdir(path)==False :
     os.mkdir(path) 

   open(path+fn, 'wb').write(fileitem.file.read())

   message = '文件 "' + fn + '" 上传成功'
   
else:
   message = '文件没有上传'
print ("Content-type:text/html")
print ()
print ('<html>')
print ('<head>')
print ('<meta charset="utf-8">')
print ('<title>用户登陆</title>')
print ('</head>')
print ('<body>')
print ('<h2>欢迎回来：%s！</h2>' % filetitle)
print ('<p>%s</p>' % message)
print ('<br/><a href="start.html">返回首页</a>')
print ('</body>')
print ('</html>')